import { getUser, allRole } from '@/api/role';

import addTree from '@/components/addTree.vue';
import { it } from 'element-plus/es/locale';

export default {
  name: 'rolePage',
  components: {
    addTree,
  },
  data() {
    return {
      tableData: [],
      total: 0,
      ShowRole: false,
      roledata: [
        {
          label: '节点1',
          id: 0,
          children: [],
        },
      ],
    };
  },
  created() {
    this.getList();
    this.getAllRole();
  },
  methods: {
    async getAllRole() {
      const res = await allRole();
      const { statusText, data } = res;
      console.log('data', data.data);

      for (const item of data.data) {
        const { pid } = item;
        const parent = data.data.find((it) => it.id === pid);
        if (parent) {
          if (!parent.children) parent.children = [];
          parent.children.push(item);
        }
      }
      // this.allRole = {
      //   label: 'root',
      //   id: 0,
      //   children: data.data,
      // };
    },
    async getList() {
      const res = await getUser();
      const { statusText, data } = res;
      if (statusText === 'OK') {
        this.tableData = data.data;
        this.total = data.total;
      }
    },
    openRoleDialog(id) {
      console.log('id', id);
      this.ShowRole = true;
    },
  },
};
